package com.swift.authority.application.config.security;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @version 1.0
 * @description JWT内容 增强器
 * @date 2022/07/03  13:11
 */
public class JwtTokenEnhancer implements TokenEnhancer {
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
        //存放拓展信息
        Map<String,Object> tokenMap = new HashMap<>();
        tokenMap.put("enhance","enhancer info");
        //存放增强内容
        ((DefaultOAuth2AccessToken)oAuth2AccessToken).setAdditionalInformation(tokenMap);
        return oAuth2AccessToken;
    }
}
